package cn.edu.nchu.comic_strip.database.dao;

import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import androidx.room.Update;

import java.util.List;

import cn.edu.nchu.comic_strip.entity.Page;

/**
 * @className: PageDao
 * @description: TODO 类描述
 * @author: Kuangkeli
 * @date: 2024/05/24 18:56
 **/
@Dao
public interface PageDao {
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void inserts(Page... page);

    @Delete
    void deletes(Page... pages);

    @Update
    void update(Page... pages);

    @Query("SELECT * FROM page ORDER BY id DESC")
    List<Page> getAllPages();

    @Query("SELECT * FROM page WHERE is_collection = 1")
    List<Page> getAllCollectionPages();

    @Query("SELECT * FROM page WHERE is_bookmark = 1")
    List<Page> getAllBookmarkPages();

    @Query("UPDATE page SET is_collection = 1 WHERE id = :pageId")
    void addCollection(int pageId);

    @Query("UPDATE page SET is_collection = 0 WHERE id = :pageId")
    void removeCollection(int pageId);

    @Query("UPDATE page SET is_bookmark = 1 WHERE id = :pageId")
    void addBookmark(int pageId);

    @Query("UPDATE page SET is_bookmark = 0 WHERE id = :pageId")
    void removeBookmark(int pageId);

    @Query("SELECT * FROM page WHERE book_id = :bookId")
    List<Page> getPagesByBookId(int bookId);

    @Query("SELECT * FROM page WHERE is_collection = 1")
    List<Page> getCollection();

    @Query("SELECT * FROM page WHERE is_collection = 1 and book_id = :bookId")
    List<Page> getCollectionByBookId(int bookId);

    @Query("SELECT * FROM page WHERE is_bookmark = 1")
    List<Page> getBookMark();

    @Query("SELECT * FROM page WHERE is_bookmark = 1 and book_id = :bookId")
    List<Page> getBookMarkByBookId(int bookId);
}
